Skip to content

feat: data-mageforge attribute handling#189

Merged
dermatz merged 14 commits into
mainfrom
feat/data-mageforge-attribute
Jun 1, 2026
Merged

feat: data-mageforge attribute handling#189
dermatz merged 14 commits into
mainfrom
feat/data-mageforge-attribute

Conversation

@dermatz
Copy link
Copy Markdown
Member

@dermatz dermatz commented May 27, 2026

This pull request introduces significant improvements to the MageForge Inspector system, focusing on how block metadata is injected, parsed, and interacted with, both on the backend (PHP) and frontend (JavaScript and CSS). The changes move from using HTML comment markers to using data attributes for block metadata, making the inspector more robust, especially when blocks are rendered inside attribute values or complex CMS structures. There are also accessibility and usability enhancements for the inspector UI.

Inspector Metadata Injection and Parsing

  • Switched from wrapping block output with HTML comment markers to injecting data-mageforge-id and data-mageforge-block attributes directly on the first root HTML element of each block, ensuring safer and more reliable metadata embedding, especially for content used inside HTML attributes. The metadata is now escaped for HTML attributes using Magento's Escaper class, and CMS block IDs are included in the metadata. (InspectorHints.php, InspectorHintsFactory.php) [1] [2] [3] [4]
  • Updated the frontend DOM parsing logic to detect blocks using these new data attributes, replacing the old comment-based approach. Block lookup and containment logic was refactored to support multi-root CMS/PageBuilder content and to make block detection more reliable. (dom.js)

Inspector UI and Accessibility Improvements

  • The inspector floating button is now a div with appropriate ARIA roles and keyboard handling, improving accessibility and avoiding unwanted theme CSS overrides. Keyboard support for activation (Enter/Space) and focus outlines were added for better usability. (inspector.js, inspector.css) [1] [2] [3]
  • Inspector button styling was improved for consistency and accessibility, including font size, line height, and focus states. (inspector.css) [1] [2]

Codebase Cleanup and Refactoring

  • Removed legacy code for comment-based block detection and unnecessary block detection caches, simplifying both backend and frontend implementations. (InspectorHints.php, inspector.js, dom.js) [1] [2] [3]
  • Added a factory class for InspectorHints to support dependency injection and instantiation via Magento's object manager. (InspectorHintsFactory.php)

Minor Backend Adjustments

  • Fixed a bug in summary display by passing the correct data structure to the summary display method in the compatibility check command. (CompatibilityCheckCommand.php) [1] [2]

Inspector Metadata Injection and Parsing

  • Switched from HTML comments to data-mageforge-* attributes for embedding block metadata, improved HTML safety, included CMS block IDs, and used Magento's Escaper for proper encoding. (InspectorHints.php, InspectorHintsFactory.php) [1] [2] [3] [4]
  • Refactored frontend DOM parsing to use data attributes for block detection and containment, supporting complex CMS/PageBuilder structures. (dom.js)

Inspector UI and Accessibility

  • Changed inspector float button to a div with ARIA roles, keyboard activation, and improved focus styling for accessibility. (inspector.js, inspector.css) [1] [2] [3]
  • Enhanced button styling for readability and consistency. (inspector.css) [1] [2]

Codebase Cleanup

  • Removed legacy comment-based block detection and unnecessary caches, simplifying the codebase. (InspectorHints.php, inspector.js, dom.js) [1] [2] [3]

Backend Bugfix

  • Corrected summary data handling in the compatibility check command. (CompatibilityCheckCommand.php) [1] [2]

Copilot AI review requested due to automatic review settings May 27, 2026 15:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Replaces HTML-comment-based inspector markers with data-mageforge-* attributes on the first root element of each rendered block, so block output can be safely embedded inside attribute values (notably PageBuilder URLs) without corrupting markup. Also surfaces a CMS block identifier and adapts the frontend DOM/picker/tabs code to the new attribute-based discovery, including a PageBuilder multi-root fallback.

Changes:

  • Backend: inject data-mageforge-id / data-mageforge-block JSON via regex on the first opening tag and add cmsBlockId to metadata.
  • Frontend DOM: rewrite block discovery to query [data-mageforge-id], parse JSON metadata, and add a PageBuilder sibling-search fallback.
  • Frontend UI: render a "CMS Block" section when present, and let the picker still target elements inside [data-content-type] even when no block was resolved.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/Model/TemplateEngine/Decorator/InspectorHints.php Switch from comment wrappers to data-attribute injection on the first root tag; add cmsBlockId metadata.
src/view/frontend/web/js/inspector/dom.js Replace TreeWalker comment parsing with attribute-based discovery and add PageBuilder multi-root fallback.
src/view/frontend/web/js/inspector/picker.js Return inspectable target inside [data-content-type] even when no block metadata is resolved.
src/view/frontend/web/js/inspector/tabs.js Carry cmsBlockId through inherited data and render a new "CMS Block" info section.

Comment thread src/Model/TemplateEngine/Decorator/InspectorHints.php Outdated
Comment thread src/Model/TemplateEngine/Decorator/InspectorHints.php
Comment thread src/Model/TemplateEngine/Decorator/InspectorHints.php
Copilot AI review requested due to automatic review settings May 27, 2026 15:42
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread src/Model/TemplateEngine/Decorator/InspectorHints.php Outdated
Comment thread src/Model/TemplateEngine/Decorator/InspectorHints.php Outdated
dermatz and others added 2 commits June 1, 2026 09:54
* feat: add new color variables and group styles to toolbar CSS; update createMenuItem to accept groupKey

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* fix: scope purple variable and increase hover specificity for group labels

* fix: simplify warning display logic in CompatibilityChecker

* fix: rename purple color variable and update groupKey data attribute in toolbar

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 1, 2026 07:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread src/Model/TemplateEngine/Decorator/InspectorHints.php Outdated
Copilot AI review requested due to automatic review settings June 1, 2026 09:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 8 comments.

Comment thread src/view/frontend/web/js/toolbar/ui.js Outdated
Comment thread src/view/frontend/web/js/inspector/picker.js
Comment thread src/Model/TemplateEngine/Decorator/InspectorHintsFactory.php Outdated
Comment thread src/view/frontend/web/js/toolbar/ui.js Outdated
Comment thread src/view/frontend/web/js/inspector/picker.js
Comment thread src/Model/TemplateEngine/Decorator/InspectorHintsFactory.php Outdated
Comment thread src/view/frontend/web/js/inspector/dom.js
Comment thread src/view/frontend/web/js/toolbar/ui.js
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 1, 2026 09:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 11 comments.

Comment thread src/Model/TemplateEngine/Decorator/InspectorHints.php
Comment thread src/view/frontend/web/js/toolbar/ui.js
Comment thread src/view/frontend/web/js/toolbar/ui.js
Comment thread src/view/frontend/web/js/toolbar/ui.js
Comment thread src/view/frontend/web/js/toolbar/ui.js
Comment thread src/view/frontend/web/js/toolbar/ui.js
Comment thread src/view/frontend/web/js/toolbar/ui.js
Comment thread src/view/frontend/web/js/inspector.js
Comment thread src/view/frontend/web/css/inspector.css
Comment thread src/view/frontend/web/js/inspector/dom.js
Copilot AI review requested due to automatic review settings June 1, 2026 09:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Comment thread src/view/frontend/web/js/inspector.js
Comment thread src/view/frontend/web/js/inspector/dom.js
@dermatz dermatz merged commit 35975ac into main Jun 1, 2026
12 checks passed
@dermatz dermatz deleted the feat/data-mageforge-attribute branch June 1, 2026 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants